package com.gxa.p2p.controller;


import com.gxa.p2p.common.JsonResult;
import com.gxa.p2p.pojo.User;
import com.gxa.p2p.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author R
 * @data 2021-10-21 10:38
 */
@CrossOrigin
@RestController
@RequestMapping("/user")

//@Transactional
@Api(value = "用户操作的接口")
public class UserController {


    @Autowired
    UserService userService = null;

    @PostMapping("/get")
    @ApiOperation("通过ID查询用户信息的方法")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "编号",required = true,dataType = "Long")
    })
    public Map byId(@RequestParam("id") Long id){
        User user = userService.selectById(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(user);
        return jsonResult.getDataMap();
    }

    @PostMapping("/getCpnUsedList")
    public Map getCpnUsedList(@RequestBody Map map){
        System.out.println(map);
        return null;
    }

    @PostMapping("/insert")
    @ApiOperation("添加用户操作")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "user",value = "用户信息",required = true,paramType = "body")
//    })
    public void insert(User user){
        System.out.println(user);
    }


    @PostMapping("/delete")
    public Map delete(@RequestHeader String token){
        System.out.println("token:"+token);
        return null;
    }

    @PostMapping("/login")
    public Map login(HttpSession session){
        //验证登陆判断过程
        //判断通过，生成token
        //就记录session
        session.setAttribute("token","token123456");
        //返回token给前端
        return null;
    }

    @PostMapping("/index")
    public Map index(HttpSession session){
        //取出token
        Object token = session.getAttribute("token");
        System.out.println("token:"+token);
        return null;
    }


}
